home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / dos6mm.zip / HMAGAUGE.ASM < prev    next >
Assembly Source File  |  1993-03-31  |  6KB  |  150 lines

  1. ;****************************************************************************
  2. ; HMAGAUGE displays the number of free bytes in the HMA and the percentage
  3. ; of HMA space in use. Its syntax is:
  4. ;
  5. ;       HMAGAUGE
  6. ;
  7. ; HMAGAUGE relies on undocumented DOS function 4A01h (accessed through
  8. ; interrupt 2Fh) to get information about the HMA.
  9. ;****************************************************************************
  10.  
  11. code            segment
  12.                 assume  cs:code,ds:code
  13.                 org     100h
  14. begin:          jmp     main
  15.  
  16. copyright       db      "HMAGAUGE 1.0 Copyright (c) 1993 Jeff Prosise",13,10
  17.                 db      "From: PC Magazine DOS 6 Memory Management "
  18.                 db      "with Utilities",13,10,13,10
  19.  
  20.                 db      "Remaining Free Space: $"
  21. txt2            db      " bytes",13,10,"Current HMA Utilization: $"
  22. txt3            db      "%",13,10,"$"
  23.  
  24. helpmsg         db      "Displays statistics concerning DOS's utilization "
  25.                 db      "of the High Memory Area.",13,10,13,10
  26.                 db      "HMAGAUGE",13,10,"$"
  27.  
  28. errmsg1         db      "Requires DOS 5 or higher",13,10,"$"
  29. errmsg2         db      "DOS is not loaded in the HMA",13,10,"$"
  30.  
  31. ;****************************************************************************
  32. ; Procedure MAIN
  33. ;****************************************************************************
  34.  
  35. main            proc    near
  36.                 cld                             ;Clear direction flag
  37.                 mov     si,81h                  ;Point SI to the command line
  38.                 call    scanhelp                ;Scan for a "/?" switch
  39.                 jnc     main1                   ;Branch if not found
  40.  
  41.                 mov     ah,09h                  ;Display help text
  42.                 mov     dx,offset helpmsg
  43.                 int     21h
  44.                 jmp     exit                    ;Exit
  45.  
  46. main1:          mov     ah,30h                  ;Check the DOS version and
  47.                 int     21h                     ;abort if it's not 5.0 or
  48.                 cmp     al,5                    ;later
  49.                 jae     main2
  50.  
  51.                 mov     dx,offset errmsg1       ;Display error message
  52. error:          mov     ah,09h                  ;and terminate
  53.                 int     21h
  54.                 mov     ax,4C01h
  55.                 int     21h
  56.  
  57. main2:          mov     ax,3306h                ;Make sure DOS is loaded
  58.                 int     21h                     ;in the HMA
  59.                 test    dh,10h
  60.                 jnz     main3
  61.                 mov     dx,offset errmsg2       ;Error if it is not
  62.                 jmp     error
  63. ;
  64. ; Compute and display HMA utilization statistics.
  65. ;
  66. main3:          mov     ax,4A01h                ;Get free space
  67.                 int     2Fh
  68.  
  69.                 mov     ah,09h                  ;Display header
  70.                 mov     dx,offset copyright
  71.                 int     21h
  72.  
  73.                 push    bx                      ;Save byte count in BX
  74.                 mov     ax,bx                   ;Display number of bytes
  75.                 call    bin2asc                 ;unallocated
  76.                 pop     bx                      ;Restore byte count
  77.  
  78.                 mov     ah,09h                  ;Display "bytes" and
  79.                 mov     dx,offset txt2          ;"Current HMA Utilization"
  80.                 int     21h
  81.  
  82.                 mov     ax,0FFF0h               ;Compute percent utilized
  83.                 sub     ax,bx
  84.                 mov     bx,100
  85.                 mul     bx
  86.                 mov     bx,0FFF0h
  87.                 div     bx
  88.                 call    bin2asc                 ;Display the result
  89.  
  90.                 mov     ah,09h                  ;Display percent sign
  91.                 mov     dx,offset txt3
  92.                 int     21h
  93.  
  94. exit:           mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  95.                 int     21h
  96. main            endp
  97.  
  98. ;****************************************************************************
  99. ; BIN2ASC displays the number in AX.
  100. ;****************************************************************************
  101.  
  102. bin2asc         proc    near
  103.                 mov     bx,10                   ;Initialize divisor word and
  104.                 xor     cx,cx                   ;digit counter
  105. b2a1:           inc     cx                      ;Increment digit count
  106.                 xor     dx,dx                   ;Divide by 10
  107.                 div     bx
  108.                 push    dx                      ;Save remainder on stack
  109.                 or      ax,ax                   ;Loop until quotient is zero
  110.                 jnz     b2a1
  111. b2a2:           pop     dx                      ;Retrieve a digit from stack
  112.                 add     dl,30h                  ;Convert it to ASCII
  113.                 mov     ah,2                    ;Display it
  114.                 int     21h
  115.                 loop    b2a2                    ;Loop until done
  116.                 ret
  117. bin2asc         endp
  118.  
  119. ;****************************************************************************
  120. ; SCANHELP scans the command line for a /? switch. If the switch is found,
  121. ; carry returns set and SI contains the switch offset. If the switch is not
  122. ; found, carry returns clear.
  123. ;****************************************************************************
  124.  
  125. scanhelp        proc    near
  126.                 push    si                      ;Save SI
  127. scanloop:       lodsb                           ;Get a character
  128.                 cmp     al,0Dh                  ;Exit if end of line
  129.                 je      scan_exit
  130.                 cmp     al,"?"                  ;Loop if not "?"
  131.                 jne     scanloop
  132.                 cmp     byte ptr [si-2],"/"     ;Loop if not "/"
  133.                 jne     scanloop
  134.  
  135.                 add     sp,2                    ;Clear the stack
  136.                 sub     si,2                    ;Adjust SI
  137.                 stc                             ;Set carry and exit
  138.                 ret
  139.  
  140. scan_exit:      pop     si                      ;Restore SI
  141.                 clc                             ;Clear carry and exit
  142.                 ret
  143. scanhelp        endp
  144.  
  145. code            ends
  146.                 end     begin
  147. code            ends
  148.                 end     begin
  149.  
  150.